package phyml.view;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import grith.jgrith.cred.AbstractCred;
import grith.jgrith.cred.Cred;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * Project: grisu
 * <p/>
 * Written by: Markus Binsteiner
 * Date: 19/08/13
 * Time: 11:52 AM
 */
public class PhyMLNeSISubmitPanel {
    private JPanel panel1;
    private JCheckBox submitJobToNeSICheckBox;
    private JPanel optionsJPanel;
    private PhyMLNeSIOptionsPanel optionsPanel;

    public PhyMLNeSISubmitPanel() {
        $$$setupUI$$$();
        submitJobToNeSICheckBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                    System.out.println("NOT CHECKED");
                } else {
                    System.out.println("CHECKED");
                }
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("PhyMLNeSILoginForm");
        frame.setContentPane(new PhyMLNeSISubmitPanel().panel1);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    private void createUIComponents() {
        optionsPanel = new PhyMLNeSIOptionsPanel();
        optionsJPanel = optionsPanel.getPanel();

        Cred c = AbstractCred.getExistingCredential();

        if (c != null && c.isValid()) {
            optionsPanel.switchTo("READY");
        } else {
            optionsPanel.switchTo("LOGIN");
        }

    }

    public JPanel getPanel() {
        return panel1;
    }

    public boolean isSelected() {
        return submitJobToNeSICheckBox.isSelected();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        panel1 = new JPanel();
        panel1.setLayout(new FormLayout("fill:d:grow", "center:d:noGrow,top:5dlu:noGrow,center:max(d;4px):grow"));
        submitJobToNeSICheckBox = new JCheckBox();
        submitJobToNeSICheckBox.setText("Submit job to NeSI2");
        CellConstraints cc = new CellConstraints();
        panel1.add(submitJobToNeSICheckBox, cc.xy(1, 1));
        panel1.add(optionsJPanel, cc.xy(1, 3, CellConstraints.DEFAULT, CellConstraints.TOP));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return panel1;
    }
}
